![]() |
Essentials of C++: Section XIV |
Input and Output Standard 'C' included the scanf and printf functions to
handle input and output. While they are still part of C++, they are not as
popular as the newer approach found in C++ and are not described here.
In C++ input and output is most often viewed in terms of various kinds of data paths or streams. There are a number of different kinds of streams, each represented by a class. The collection of such classes forms an inheritance structure as shown here:
![]() The classes that are most important for our purposes are:
The first three of these and the last one are declared in the file
'iostream.h'. The other two are declared in 'fstream.h'. A. The Base Class ios: Its Data
Members
A number of these flags or bit fields have defaults:
Discussion in 'The Story of C++" A second set of flags handles error states. These
states represent a greater level of detail than we need to examine here
but can be summarized as four states with which there are corresponding
member functions as described later. The four states are:
Discussion in "The Story of C++" There are three other ios data members
relevant to the state of a stream:
Finally, there is an enumerated type for indicating the relationship between the stream and some file. (Input and output devices are considered to be files as far as C++ is concerned.) In declaring a stream we attach the stream to a file and open the |